/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rm.beans;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.rm.entidades.Jugadores;
import org.rm.entidades.Partida;
import org.rm.entidades.jpa.JugadoresJpaController;
import org.rm.entidades.jpa.PartidaJpaController;

/**
 *
 * @author ffbeltran
 */
public class FormularioBean {
    
    private Map<String, Boolean> visibilidadForms;
    
    public FormularioBean() {
        visibilidadForms = new HashMap<String, Boolean>();
        for (String nombre : ControladorUtil.getNombresEntidades()) {
            visibilidadForms.put(nombre, false);
        }
    }

    public String cambiaVisibilidad() {
        String form = ControladorUtil.getParam("nombreForm");
        if(visibilidadForms.containsKey(form))
            visibilidadForms.put(form, !visibilidadForms.get(form));
        return null;
    }

    public Map<String, Boolean> getVisibilidad() {
        return visibilidadForms;
    }

    public List<SelectItem> getJugadores() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        for (Iterator<Jugadores> it = JugadoresJpaController.findJugadoresEntities().iterator(); it.hasNext();) {
            Jugadores jugador = it.next();
            result.add(new SelectItem(jugador, jugador.getNombre()));
        }
        return result;
    }

    public List<SelectItem> getPartidas() {
        List<SelectItem> partidas = new ArrayList<SelectItem>();
        List <Partida> partidasBean = PartidaJpaController.findPartidaEntities();
        for (Iterator<Partida> it = partidasBean.iterator(); it.hasNext();) {
            Partida partida = it.next();
            partidas.add(new SelectItem(partida.getId(), partida.getId().toString()));
        }
        return partidas;
    }

    public List<SelectItem> getCompartido() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        for (int i = 0; i < 11; i++) {
            Integer porcentaje = i * 10;
            result.add(new SelectItem(porcentaje, porcentaje + "%"));
        }
        return result;
    }

    public List<SelectItem> getViaje1() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem(5, "Normal"));
        result.add(new SelectItem(10, "Accidentado o Moderadamente Peligroso"));
        result.add(new SelectItem(15, "Extremadamente Peligroso"));
        return result;
    }

    public List<SelectItem> getViaje3() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem(new Double(1), "Andando y Consciente"));
        result.add(new SelectItem(new Double(0.1), "Inconsciente"));
        result.add(new SelectItem(new Double(0.2), "Mar o Aire"));
        return result;
    }

    public List<SelectItem> getManiobra1() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem(new Double(0.5), "Rutina a Normal"));
        result.add(new SelectItem(new Double(1), "Difícil - Extrem. Difícil"));
        result.add(new SelectItem(new Double(2), "Prácticamente Imposible - Absurda"));
        return result;
    }

    public List<SelectItem> getCritico1() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem(5, "A"));
        result.add(new SelectItem(10, "B"));
        result.add(new SelectItem(15, "C"));
        result.add(new SelectItem(20, "D"));
        result.add(new SelectItem(25, "E"));
        result.add(new SelectItem(21, "CG"));
        result.add(new SelectItem(40, "CSG"));
        return result;
    }

    public List<SelectItem> getCritico2() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem(new Double(1), "En grupo"));
        result.add(new SelectItem(new Double(0.1), "Enemigo Inconsciente"));
        result.add(new SelectItem(new Double(0.2), "Enemigo Aturdido"));
        result.add(new SelectItem(new Double(2), "Combate Individual"));
        return result;
    }
}
